package com.hkts.reportform.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassNameDateUtil
 * @Description
 * @Author yck
 * @Date2020-10-20 13:40
 * @Version V1.0
 **/
public class DateUtil {
    //获取近7天或近30天
    public static List<String> getDateArray(int value) {
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < value; i++) {
            list.add(ss.format(getYesterday(value - i)));
        }
        return list;
    }

    //获取昨天
    public static Date getYesterday() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        Date d = cal.getTime();
        return d;
    }

    //获取日期
    public static Date getYesterday(int i) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -i);
        Date d = cal.getTime();
        return d;
    }
     //获取本月1号
     public static String getThisMonth() {
         SimpleDateFormat formateMonth = new SimpleDateFormat("yyyy-MM");
         return formateMonth.format(new Date())+"-01";
     }
    //获取近7天或近30天
    public static List<String> getShowDateArray(int value) {
        SimpleDateFormat ss = new SimpleDateFormat("MM-dd");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < value; i++) {
            list.add(ss.format(getYesterday(value - i)));
        }
        return list;
    }

    public static List<Float> getHoursData(List<Float> list) {
        for (int i = 0; i < list.size(); i++) {
            float value = 0;
            Random rand = new Random();
            value = rand.nextInt(100) + 1;
            list.set(i, value);
        }
        return list;
    }
    //获取一段时间所有日期
    public static List<String> getDaysByTime(String[] dateArray) {
        List<String> list = new ArrayList<>();
        String[] dateBegs = dateArray[0].split("-");
        String[] dateEnds = dateArray[1].split("-");
        Calendar start = Calendar.getInstance();
        start.set(Integer.valueOf(dateBegs[0]), Integer.valueOf(dateBegs[1]) - 1, Integer.valueOf(dateBegs[2]));
        Long startTIme = start.getTimeInMillis();
        Calendar end = Calendar.getInstance();
        end.set(Integer.valueOf(dateEnds[0]), Integer.valueOf(dateEnds[1]) - 1, Integer.valueOf(dateEnds[2]));
        Long endTime = end.getTimeInMillis();
        Long oneDay = 1000 * 60 * 60 * 24L;
        Long time = startTIme;
        while (time <= endTime) {
            Date d = new Date(time);
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            time += oneDay;
            list.add(df.format(d));
        }
        return list;
    }
    //时间格式转换
    public  static List<String> dateListConvert(List<String> dateArray) throws ParseException {
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat ss1 = new SimpleDateFormat("MM/dd");
        for(int i=0;i<dateArray.size();i++){
            ss1.format(ss.parse(dateArray.get(i))) ;
            dateArray.set(i,ss1.format(ss.parse(dateArray.get(i))));
        }
        return dateArray;
    }
}
